{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "487cdcda",
   "metadata": {},
   "source": [
    "# week 06 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69f8e8e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#### 列表基本知识 \n",
    "- append（）、insert()、extend()\n",
    "增加append 增加在list的末尾\n",
    "插入insert 可以在指定位置增加元素\n",
    "extend 是给指定的list进行扩充\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "944ce26a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['mary', 'mike', 'jan', 'jack', 1]\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "names.append(1)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2465e3a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "insert之后的names: ['mary', 'jinshanlee', 'mike', 'jan', 'jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "names.insert(1,'jinshanlee')\n",
    "print(\"insert之后的names:\",names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "383f578d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['mary', 'mike', 'jan', 'jack', 1001, 1002, 1003, 1004, 1005]\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "stu_id = [1001,1002,1003,1004,1005]\n",
    "names.extend(stu_id)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8dab68bd",
   "metadata": {},
   "source": [
    "### 删除 remove（）、 pop（）\n",
    "- remove（）一般情况下 使用remove先用in做判断\n",
    "- pop（） 删除位置为1的这个元素（倒序、删除末尾数据）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dc9e5cd8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "remove删除的结果: ['mary', 'mike', 'jan', 'jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "\n",
    "if 1 in names:\n",
    "    names.remove(1)\n",
    "print(\"remove删除的结果:\",names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a2b751d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pop()方法的names ['mary', 'mike', 'jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "names.pop(2)\n",
    "print(\"pop()方法的names\",names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa2e3abb",
   "metadata": {},
   "source": [
    "### 索引 index\n",
    "查看该元素如1001在stu——id中第一个出现的位置索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8a1e57ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "stu_id = [1001,1002,1003,1004,1005]\n",
    "print(stu_id.index(1001))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a50d9ff5",
   "metadata": {},
   "source": [
    "### 清除数据 clear"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8c44f721",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "清除names列表后的值: []\n"
     ]
    }
   ],
   "source": [
    "names = [\"mary\",\"mike\",\"jan\",\"jack\"]\n",
    "names.clear()\n",
    "print(\"清除names列表后的值:\",names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea4b9a52",
   "metadata": {},
   "source": [
    "### 统计 count\n",
    "查看列表元素出现的个数，统计分数出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3c2b9f9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
